<?php


namespace app\xiangji\jobs;


use app\common\models\LoveScore;
use app\xiangji\services\LoveScoreService;
use think\facade\Log;
use think\queue\Job;

class GiveLoveScoreJob
{
    public function fire(Job $job, array $data)
    {
        try {
            $score = LoveScore::where('user_id', '=', $data['user_id'])->find();
            if (!$score) {
                $job->delete();
                return;
            }
            if ($job->attempts() >= 3){
                $job->delete();
                return;
            }
            LoveScoreService::updateUserScore($score, $data['score'], $data['scene']);
            $job->delete();
            return true;
        }catch (\Exception $exception){
            Log::error('发放恩爱值错误', [
                'data' => $data,
                'error' => $exception
            ]);
            $job->delete();
        }
    }
}
